import {
    getSort,
    updateOne,
    get
} from '../../utils/db'
Page({
    data: {
        page: 1, //页码
        pageSize: 5, //一页的数量
        types: [{
                src: "../../imgs/index_07.jpg",
                typename: "营养菜谱"
            },
            {
                src: "../../imgs/index_09.jpg",
                typename: "儿童菜谱"
            },
        ],
        recipes: []
    },
    //点击菜谱分类跳转
    classify() {
        wx.navigateTo({
            url: '../type/type',
        })
    },
    //点击跳转到详情页
    menuClick(e) {
        var id = e.currentTarget.id;
        wx.navigateTo({
            url: '../detail/detail?id=' + id,
        })
    },
    //页面加载时渲染
    async onLoad() {
        this.getPage()
    },
    async getPage() {
        var page = this.data.page; //当前页码
        var pageSize = this.data.pageSize; //当前有几条数据
        var skip = (page - 1) * pageSize; //每次触底加载几条数据
        var result = await getSort("menu", {
            status: 1
        }, skip, pageSize)

        var arr = result.data;
        this.setData({
            recipes: this.data.recipes.concat(arr) //当前的加上之前的数据，渲染到页面
        })
    },
    //页面触底
    onReachBottom() {
        this.data.page += 1; //页面加1 
        this.getPage()
    },
    //跳转到我的页面
    myMenu() {
        wx.switchTab({
            url: '../my/my',
        })
    },
    //跳转到营养菜谱和儿童菜谱
    menus(e) {
        var name = e.currentTarget.dataset.name;
        if (name == '营养菜谱') {
            wx.navigateTo({
                url: '../list/list?id=2fd465895fa24bea003715c7752e2f0e',
            })
        } else {
            wx.navigateTo({
                url: '../list/list?id=d52d5a735fa24bf6002eaa8d6b85d20a',
            })
        }
    }
})